//
//  AddSOSViewController.m
//  location
//
//  Created by Dongxiang Xu on 2025/5/29.
//

#import "AddSOSViewController.h"

@interface AddSOSViewController ()

@property (nonatomic,strong) UIScrollView *scrollView;

@end

@implementation AddSOSViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = RealWhiteColor;
    [self initView];
}

- (void)initView
{
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, STATUSHEIGHT, SCREEN_WIDTH, 44)];
    title.font = MEDIUM_FONT(18);
    title.textAlignment = NSTextAlignmentCenter;
    title.text = @"添加紧急联系人";
    title.textColor = RealBlackColor;
    [self.view addSubview:title];
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NAVHEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-NAVHEIGHT)];
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
    
    UILabel *sos = [[UILabel alloc] initWithFrame:CGRectMake(28, 21, SCREEN_WIDTH-56, 20)];
    sos.font = MEDIUM_FONT(16);
    sos.textColor = RealBlackColor;
    sos.text = @"选择成员";
    [_scrollView addSubview:sos];
    
    NSArray *array = @[@{@"avatar":@"",@"nickname":@"张大千"},@{@"avatar":@"",@"nickname":@"泽连斯基"},@{@"avatar":@"",@"nickname":@"布莱恩特"},@{@"avatar":@"",@"nickname":@"罗纳尔多"}];
    for (int i = 0; i < array.count; i ++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(sos.frame)+11+i*78, SCREEN_WIDTH, 78)];
        [_scrollView addSubview:button];
        
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(32, 13, 52, 52)];
        [img.layer setCornerRadius:26];
        img.layer.masksToBounds = YES;
        img.backgroundColor = GraryLightColor;
        [button addSubview:img];
        
        UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(img.frame)+16, img.y, SCREEN_WIDTH-CGRectGetMaxX(img.frame)-92 ,img.height)];
        name.textColor = RealBlackColor;
        name.font = MEDIUM_FONT(16);
        name.text = array[i][@"nickname"];
        [button addSubview:name];
        
        UIImageView *box = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60, (button.height-22)/2, 22, 22)];
        [box.layer setBorderWidth:1];
        box.layer.masksToBounds = YES;
        [box.layer setCornerRadius:6];
        [button addSubview:box];
        UIImageView *boxImg = [[UIImageView alloc] initWithFrame:CGRectMake(4, 4, 14, 14)];
        [boxImg setImage:[UIImage imageNamed:@"box_sel"]];
        [box addSubview:boxImg];
        
        box.backgroundColor = NormalMainColor;
        box.layer.borderColor = NormalMainColor.CGColor;
        
        if (i==(array.count-1)) {
            [_scrollView setContentSize:CGSizeMake(0, CGRectGetMaxY(button.frame)+32)];
        }
    }
    
}

@end
